<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>红光理疗后台管理</title>

    <!--<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900italic,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic' rel='stylesheet' type='text/css'>-->

    <!--<link rel="icon" type="image/png" sizes="16x16" href="assets/img/favicon-16x16.png">
    <link rel="icon" type="image/png" sizes="32x32" href="assets/img/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="96x96" href="assets/img/favicon-96x96.png">-->
    <!--<script src="../bower_components/angular/angular.js"></script>-->
    <!--<script src="cdn.bootcss.com/angular.js/1.5.5/angular-animate.js"></script>-->
    <script src="//cdn.bootcss.com/angular.js/1.5.5/angular.min.js"></script>
    <!-- build:css({.tmp/serve,src}) styles/vendor.css -->
    <!-- bower:css -->
    <!-- run `gulp inject` to automatically populate bower styles dependencies -->
    <!-- endbower -->
    <!-- endbuild -->

    <!-- build:css({.tmp/serve,src}) styles/auth.css -->
    <!-- inject:css -->
    <!-- css files will be automatically insert here -->
    <!-- endinject -->
    <!-- endbuild -->
    <style>
        .is_fail {
            border: 1px solid #ff0000;
        }
        
        .span_fff {
            color: #fff;
        }
        
        .span_fff:before {
            color: #fff !important;
        }
    </style>
</head>

<body ng-app="login" ng-controller="mycon">
    <main class="auth-main" ng-if="is_login" style="  background: -webkit-radial-gradient(#01a0da, #021b25);">
        <div class="auth-block">
            <h1>欢迎登录</h1>

            <form class="form-horizontal">
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
                    <div class="col-sm-10">
                        <ng-form name=usermobile>
                            <input type="text" name="usermobile" class="form-control" ng-click="clear_tishi()" ng-class="{'is_fail':usermobile.usermobile.$error.pattern}" id="input2" placeholder="请输入11位数字手机号" ng-model="user_login.mobile" pattern="^\d{11}$">
                        </ng-form>
                        <!--<input type="text" class="form-control" id="inputEmail3" placeholder="请输入手机号">-->
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                    <div class="col-sm-10">
                        <input type="password" class="form-control" id="inputPassword3" placeholder="密码" ng-click="clear_tishi()" ng-model="user_login.password">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default btn-auth" ng-click="login()">登录</button>
                        <h4 ng-show="tishi" style="position: absolute;color: red;top: 0;left: 20%;">{{tishi}}</h4>
                        <a href class="forgot-pass" ng-click="is_login_fn(1)">忘记密码/首次登录</a>
                    </div>
                </div>
            </form>

        </div>
    </main>

    <main class="auth-main" ng-if="!is_login" style=" background: -webkit-radial-gradient(#01a0da, #021b25);">
        <div class="auth-block" style="    position: relative;">
            <div style="    display: block;position: absolute;top: 5%;left: 0;font-size: 17px;" class="col-xs-2 " ng-click="is_login_fn(2);clear_tishi()"><i class="ion-chevron-left"></i></div>
            <h1>设置帐号密码</h1>
            <form class="form-horizontal">
                <div class="form-group">
                    <label for="input1" class="col-sm-2 control-label">手机号</label>
                    <div class="col-sm-10">
                        <ng-form name=someForms>
                            <input type="text" name="usermobile" class="form-control " ng-class="{'is_fail':someForms.usermobile.$error.pattern}" id="input2" placeholder="请输入11位数字手机号" ng-model="user.mobile" pattern="^\d{11}$">
                        </ng-form>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-4">
                        <label class="radio-inline custom-radio nowrap">
                            <input type="radio" name="inlineRadioOptions" id="inlineRadio1" ng-checked="is_type=='lost_admin_password'" ng-click="fn_is_type('lost_admin_password')"> 
                            <span class="span_fff">忘记密码</span>
                        </label>
                    </div>
                    <div class="col-md-4">
                        <label class="radio-inline custom-radio nowrap">
                            <input type="radio" name="inlineRadioOptions" id="inlineRadio2" ng-checked="is_type=='active'" ng-click="fn_is_type('active')"> 
                            <span  class="span_fff">首次登录</span>
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-2 control-label">验证码</label>
                    <div class="col-sm-7">
                        <ng-form name=someForm>
                            <input type="text" name="usercode" class="form-control" ng-class="{'is_fail':someForm.usercode.$error.pattern}" id="input2" placeholder="请输入数字验证码" ng-model="user.code" pattern="^\d{4,8}$">
                        </ng-form>
                    </div>
                    <div class="col-sm-3 ">
                        <button type="submit" class="btn btn-info btn-auth " ng-click="get_code()">
                            <span ng-show="time<=1">获取验证码</span>
                            <span ng-show="time>1">{{time}}</span>
                        </button>
                    </div>
                </div>
                <div class="form-group ">
                    <label for="input2 " class="col-sm-2 control-label">设置密码</label>
                    <div class="col-sm-10 ">
                        <ng-form name=password>
                            <input type="password" name="userpwd" class="form-control" ng-class="{'is_fail':password.userpwd.$error.pattern}" id="input3" placeholder="8-20位字母、数字、下划线" ng-model="user.password" pattern="^\w{8,20}$">
                        </ng-form>
                    </div>
                </div>
                <div class="form-group ">
                    <label for="input2 " class="col-sm-2 control-label ">验证密码</label>
                    <div class="col-sm-10 ">
                        <ng-form name=password>
                            <input type="password" name="oldpwd" class="form-control" ng-class="{'is_fail':password.oldpwd.$error.pattern}" id="input4" placeholder="请再次输入密码" ng-model="user.oldpwd" pattern="^\w{8,20}$">
                        </ng-form>
                    </div>
                </div>
                <div class="form-group ">
                    <div class="col-sm-offset-2 col-sm-10 ">
                        <button class="btn btn-info btn-auth " ng-click="SetUp()">确定</button>
                        <h4 ng-show="tishi" style="position: absolute;color: red;top: 0;left: 20%;">{{tishi}}</h4>
                    </div>
                </div>
            </form>

        </div>
    </main>
    <script>
        var app = angular.module('login', []);
//         var my_url = "http://127.0.0.1:5959"; //本地 接口地址//
//         var go_url = "http://127.0.0.1:3000"; //本地 转跳地址

        //服务器 转跳地址 以及连接
        var my_url = "http://app.quanminkang.com.cn/api"; // 接口地址
        var go_url = "http://app.quanminkang.com.cn/manager"; // 转跳地址

        app.controller('mycon', function($scope, $http) {
            $scope.is_type = 'lost_admin_password';
            $scope.fn_is_type = function(val) {
                $scope.is_type = val;
            }
            $scope.is_login = true;
            $scope.is_login_fn = function(val) {
                if (val == 1) {
                    $scope.is_login = false;
                } else {
                    $scope.is_login = true;
                }
            }

            $scope.user = { //首次登录，或者找回密码
                "mobile": "",
                "code": "",
                "password": "",
                "oldpwd": ""
            }
            $scope.user_login = { //用户登录信息
                "mobile": "",
                "password": ""
            }

            $scope.tishi = '';

            $scope.clear_tishi = function() {
                $scope.tishi = '';
            };
            //用户登录验证
            $scope.login = function() {
                if (!$scope.user_login.mobile) {
                    return $scope.tishi = '请输入手机号'
                }
                if (!$scope.user_login.password) {
                    return $scope.tishi = '请输入密码'
                }
                is_log_in($scope.user_login);
            };
            //登录接口
            function is_log_in(opt) {

                $http.post(my_url + '/admin/log_in', opt)
                    .then(function(res) {
                        console.log(res);
                        if (res.data.success) { //登录成功转跳
                            localStorage.setItem('user_inof', JSON.stringify(res.data.info)); //存入本地
                            localStorage.setItem('token', res.data.info.access_token); //存入本地
                            location.href = go_url + "/#/console";
                        } else {
                            $scope.tishi = res.data.data;
                        }
                    });
            }
            $scope.time = 0;
            var t = '';
            //获取验证码
            var is_code = true;
            $scope.get_code = function() {
                if (!$scope.user.mobile) {
                    return $scope.tishi = '请输入手机号'
                }
                if (!is_code) {
                    return
                }
                var is_type = $scope.is_type;
                $http.post(my_url + '/users/get_code', {
                        mobile: $scope.user.mobile,
                        code_type: is_type
                    })
                    .then(function(res) {
                        if (res.data.success) {
                            $scope.time = 60;
                            t = setInterval(function() {
                                $scope.$apply(function() {
                                    $scope.time--;
                                });
                                is_code = false;
                                if ($scope.time < 1) {
                                    is_code = true;
                                    clearInterval(t);
                                }
                            }, 1000);
                        } else {
                            $scope.tishi = res.data.data;
                        }
                    })
            }

            $scope.SetUp = function() { //设置密码
                if (!$scope.user.mobile) {
                    return $scope.tishi = '请输入手机号'
                }
                if (!$scope.user.code) {
                    return $scope.tishi = '请输入验证码'
                }
                if (!$scope.user.password) {
                    return $scope.tishi = '请输入密码'
                }
                if ($scope.user.password !== $scope.user.oldpwd) {
                    return $scope.tishi = '两次输入密码不一致'
                }
                SetUp();
            }

            function SetUp() {
                var opt = {
                    "mobile": $scope.user.mobile,
                    "code": $scope.user.code,
                    "password": $scope.user.password
                };
                $http.post(my_url + '/admin/register_admin', opt)
                    .then(function(res) {
                        if (res.data.success) {
                            alert('设置成功');
                             is_log_in(opt);
                        } else {
                            $scope.tishi = res.data.data;
                        }
                    });

            }


        });
    </script>
</body>

</html>